package com.yqw.onlineDocs.manager.websocket;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import javax.annotation.Resource;

/**
 * WebSocket配置类
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Resource
    private DocumentEditHandler documentEditHandler;

    @Resource
    private DocumentWsHandshakeInterceptor documentWsHandshakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 注册文档编辑WebSocket处理器
        registry.addHandler(documentEditHandler, "/ws/document/edit")
                .addInterceptors(documentWsHandshakeInterceptor)
                .setAllowedOrigins("*");
    }
}